package com.ruoyi.web.controller.workflow;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.workflow.domain.vo.StatementItemVo;
import com.ruoyi.workflow.service.IStatementItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * StatementItemController
 *
 * @author xiaodu
 * @date 2023/7/28
 */
@RestController
@RequestMapping("/workflow/statementItem")
public class StatementItemController extends BaseController {

    @Autowired
    private IStatementItemService statementItemService;

    /**
     * 获取结算单明细
     * 用于预约信息表的结算单： 根据预约表的id获得
     */
    @PreAuthorize("@ss.hasPermi('workflow:statementItem:list')")
    @GetMapping(value = "itemByAppointmentInfoId/{appointmentInfoId}")
    public AjaxResult getStatementItemByAppointmentInfoId(@PathVariable Long appointmentInfoId)
    {
        //查询结算单明细
        Map<String, Object> resultMap = statementItemService.getStatementItemByAppointmentInfoId(appointmentInfoId);
        return AjaxResult.success(resultMap);
    }

    /**
     * 获取结算单明细
     * 用于结算单表的结算单： 根据结算单表的id获得
     */
    @PreAuthorize("@ss.hasPermi('workflow:statementItem:list')")
    @GetMapping(value = "itemByStatementId/{statementId}")
    public AjaxResult getStatementItemByStatementId(@PathVariable Long statementId)
    {
        //查询结算单明细
        Map<String, Object> resultMap = statementItemService.getStatementItemByStatementId(statementId);
        return AjaxResult.success(resultMap);
    }

    /**
     * 保存在消费中结算单明细的服务项 【包含：新增，更新，删除】
     *
     * @param statementItemVo - Vo对象 新增,更新,删除的列表
     * @return 返回保存的条数
     */
    @PreAuthorize("@ss.hasPermi('workflow:statementItem:save')")
    @PostMapping(value = "save")
    public AjaxResult saveStatementItem(@RequestBody StatementItemVo statementItemVo)
    {
        statementItemService.saveStatementItem(statementItemVo);
        return AjaxResult.success("结算单明细保存成功");
    }

    /**
     * 确认支付
     * @param statementId 结算单的id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('workflow:statementItem:pay')")
    @PutMapping(value = "pay")
    public AjaxResult payStatementItem(Long statementId,BigDecimal preferentialPrice)
    {
        statementItemService.payStatementItem(statementId,preferentialPrice);
        return AjaxResult.success("支付成功");
    }
}
